// src/chat/chat.controller.ts
import { Controller, Get, Query, UnauthorizedException, HttpCode,HttpStatus, UseGuards } from '@nestjs/common';
import { ChatService } from './chat.service';
import { Public } from "@src/login/decorators/public.decorator"
import { AuthGuard } from '@nestjs/passport';

@Controller('/v1/api/chat')
export class ChatController {
  constructor(private readonly chatService: ChatService) {}

  @UseGuards(AuthGuard('jwt'))
  @Public()
  @HttpCode(HttpStatus.OK)
  @Get('history')
  async getChatHistory(
    @Query('userId') userId: string,
    @Query('otherUserId') otherUserId: string,
  ) {
    const data = await this.chatService.getChatHistory(userId, otherUserId);
    if (!data) {
      throw new UnauthorizedException()
    } else {
      return {
        code: 200,
        data,
        message: 'ok'
      };
    }
  }
}